package top.superflow.flow.runtime.inf.defaults

import top.superflow.exception.Exceptable
import top.superflow.flow.runtime.inf.GeneralRequest
import top.superflow.lang.{CollectionUtils, StringUtils}

class DefaultGeneralRequest extends GeneralRequest with Exceptable{

  def getParameterNames: Iterable[String] = parameters.keys

  def addParameter(paramName : String, param : Any): Unit ={
    if(StringUtils.isBlank(paramName)){
      throwRequestUnsupportedException("The parameter name should not be blank!")
    }

    if(getParameters.contains(paramName)){
      throwRequestUnsupportedException("There is already a parameter named {} exists", paramName)
    }

    this.parameters.put(paramName, param)
  }

  def addParameters(params : Map[String, Any]): Unit ={
    if(CollectionUtils.isEmpty(params)){
      return
    }

    this.parameters ++= params
  }

  def getBody: Any = this.requestBody

}
